package cn.fsd.controller;

import cn.fsd.service.BaiduService;
import cn.fsd.vo.PointBean;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/baidu",produces = "application/json;charset=utf-8")
@Api(value = "利用百度api实现的相关功能",description = "供其他模块调用百度api")
public class BaiduController {

    @Autowired
    BaiduService baiduService;

    @GetMapping("/getGeo") //get + /baidu/getGeo
    @ApiOperation(value = "查询地址对应的经纬度")
    public ResultBean<double[]> getGeo(@RequestParam String address){
        double[] geo = baiduService.getGeoByAddress(address);
        if(geo==null) return ResultBean.error();
        else return ResultBean.success(geo);
    }

    @GetMapping("/getDistenceAndTime") //get + /baidu/getDistenceAndTime
    @ApiOperation(value = "查询两地的行驶距离(与时间)")
    public ResultBean<double[]> getDistenceAndTime(@RequestParam String origin,@RequestParam String destination){
        double[] distenceAndTime = baiduService.getDistenceAndTime(origin, destination);
        if(distenceAndTime==null) return ResultBean.error();
        else return ResultBean.success(distenceAndTime);
    }
}
